package com.javabasic.algorithm.leetcode;

import java.util.ArrayList;
import java.util.List;

/**
 * @author xiongmin
 * @version 0.0.1
 * @description Created by work on 2021/10/13 11:03 下午 二叉树的中序遍历结果
 * @see
 */
public class BinaryTreeInorderTraversal {


    /**
     * 递归解法，遍历二叉树的中序遍历
     * @param root
     * @return
     */
    public List<Integer> inorderTraversal(TreeNode root) {
        List<Integer> result = new ArrayList<>();
        getBinaryTreeInOrder(root,result);
        return result;
    }

    private void getBinaryTreeInOrder(TreeNode root, List<Integer> result) {
        if (root == null) return;
        getBinaryTreeInOrder(root.left, result);
        result.add(root.val);
        getBinaryTreeInOrder(root.right, result);
    }
}
